package nl.rintcius.groovy

import junit.framework.TestCase

public class ExpandoDslTest extends TestCase {
    
    public void testDsl() {
        String text = """
        nr1 {
          s = "littleString"
          l = [1,2,3]
          m = [1:2]
          nested = {i = it + l.first()}
          nested(5)
          xxx { r = "t" }
        }
        nr2 {
          t = "string"
          nr1s = "refto " + root.nr1.s
        }
        nr3(10) {
          amap(i:9,j:8)
          alist(1,2,1+2)
        }
        """

		ExpandoDsl expandoDsl = new ExpandoDsl(text)
        expandoDsl.setRootProperty = true
		Expando root = expandoDsl.create()

		//println(root) // can only print if expandoDsl.setRootProperty = false
		assertEquals("littleString", root.nr1.s)
		assertEquals([1,2,3], root.nr1.l)
		assertEquals([1:2], root.nr1.m)
		assertEquals(6, root.nr1.i)
		assertEquals("t", root.nr1.xxx.r)
		assertEquals("string", root.nr2.t)
		assertEquals("refto littleString", root.nr2.nr1s)
		assertEquals(10, root.nr3.value)
		assertEquals(10, root.nr3.valueList[0])
		assertEquals(9, root.nr3.amap.i)
		assertEquals(8, root.nr3.amap.j)
		assertEquals([1,2,3], root.nr3.alist.valueList)
    }
}
